Assignemnt #68 and 66th program
Code
///Name: Derrick Andreasen
///Period: 7
///Program name: 66th Program
///File name: Sixt6Prog.java
///Date Finished:11/20/2015
import java.util.Scanner;
public class Sixt6Prog
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int hi = 1000, lo = 1, guess = (lo + hi) / 2;
String answer;
System.out.println( "Think of a number from 1 to 1000. I'll try to guess it." );
System.out.println( "My guess is " + guess + ". Am I too (h)igh, too (l)ow, or (c)orrect?" );
System.out.println( ">" );
answer = keyboard.next();
while(!answer.equals("c"))
{
if(answer.equals("h"))
{
hi = guess;
guess = (lo + hi)/2;
System.out.println( "My guess is " + guess + ". Am I too (h)igh, too (l)ow, or (c)orrect?" );
System.out.println( ">" );
answer = keyboard.next();
}
else if(answer.equals("l"))
{
lo = guess;
guess = (lo + hi)/2;
System.out.println( "My guess is " + guess + ". Am I too (h)igh, too (l)ow, or (c)orrect?" );
System.out.println( "> " );
answer = keyboard.next();
}
}
System.out.println( "\nHa! I am the greates guesser in the world" );
}
}
Picture of the output